
// 右上角 - 下拉图标交互
document.addEventListener('DOMContentLoaded', function() {
    // 获取所有下拉按钮
    const dropdownBtns = document.querySelectorAll('.profile-btn');

    // 为每个下拉按钮绑定事件
    dropdownBtns.forEach(btn => {
        const dropdown = btn.closest('.profile-dropdown').querySelector('.dropdown-menu');
        const caret = btn.querySelector('.fa-caret-down');

        // 点击按钮切换菜单
        btn.addEventListener('click', function(e) {
            e.stopPropagation(); // 阻止事件冒泡
            const isActive = dropdown.classList.contains('active');

            // 关闭所有其他菜单
            closeAllDropdowns();

            // 切换当前菜单
            if (!isActive) {
                dropdown.classList.add('active');
                caret.classList.add('fa-rotate-180'); // 箭头动画
            }
        });

        // 点击菜单内部保持打开
        dropdown.addEventListener('click', function(e) {
            e.stopPropagation();
        });
    });

    // 点击页面其他区域关闭菜单
    document.addEventListener('click', function() {
        closeAllDropdowns();
    });

    // 关闭所有下拉菜单的函数
    function closeAllDropdowns() {
        document.querySelectorAll('.dropdown-menu').forEach(menu => {
            menu.classList.remove('active');
        });
        document.querySelectorAll('.fa-caret-down').forEach(caret => {
            caret.classList.remove('fa-rotate-180');
        });
    }
});


function showToast(message, type = 'success', duration = 3000) {
    console.log('显示提示：showToast');
    // 类型配置映射
    const typeConfig = {
        success: {
            icon: 'fa-check-circle',
            className: 'toast-success'
        },
        warning: {
            icon: 'fa-exclamation-triangle',
            className: 'toast-warning'
        },
        error: {
            icon: 'fa-times-circle',
            className: 'toast-error'
        }
    };

    // 创建容器
    const toast = document.createElement('div');
    toast.className = `custom-toast ${typeConfig[type].className}`;

    // 填充内容
    toast.innerHTML = `
        <i class="fas ${typeConfig[type].icon} toast-icon"></i>
        <span class="toast-message">${message}</span>
    `;

    // 添加到DOM
    document.body.appendChild(toast);

    // 自动消失逻辑
    setTimeout(() => {
        toast.style.animation = 'slideOut 0.3s ease-out';
        setTimeout(() => toast.remove(), 300);
    }, duration);
}